package com.ddwl.gate.service;

import com.ddwl.common.util.UUIDGenerator;
import com.ddwl.gate.dao.MobileNumInfoDao;
import com.ddwl.gate.model.MobileNumInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author hemiaojun
 * @Date 2020/10/13 19:07
 */
@Service
public class MobileNumInfoService {

    @Resource
    private MobileNumInfoDao mobileNumInfoDao;

    public MobileNumInfo getByMobile(String mobile) {
        MobileNumInfo mobileNumInfo = new MobileNumInfo();
        mobileNumInfo.setMobile(mobile);
        return mobileNumInfoDao.selectOne(mobileNumInfo);
    }

    public void add(MobileNumInfo mobileNumInfo) {
        MobileNumInfo exist=getByMobile(mobileNumInfo.getMobile());
        if (null != exist) {
            mobileNumInfo.setId(exist.getId());
            mobileNumInfoDao.updateByPrimaryKeySelective(mobileNumInfo);
        }else{
            mobileNumInfo.setId(UUIDGenerator.getShortUUID());
            mobileNumInfoDao.insert(mobileNumInfo);
        }
    }

    public List<MobileNumInfo> getAll() {
        return mobileNumInfoDao.getAll();
    }

    public void changeId(Map<String, String> map) {
        mobileNumInfoDao.changeId(map);
    }
}
